<?php
/**
 * CampaignsApi
 * PHP version 5
 *
 * @category Class
 * @package  AmazonAdvertisingApi
 * @author   vv_guo
 * @link    https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api
 */

/**
 * Amazon Ads API for Sponsored Display
 *
 * This API enables programmatic access for campaign creation, management, and reporting for Sponsored Display campaigns. For more information on the functionality, see the [Sponsored Display Support Center](https://advertising.amazon.com/help#GTPPHE6RAWC2C4LZ). For API onboarding information, see the [account setup](https://advertising.amazon.com/API/docs/en-us/guides/onboarding/overview) topic.<br/><br/> > This specification is available for download from the **[Advertising API developer portal](https://d3a0d0y2hgofx6.cloudfront.net/openapi/en-us/sponsored-display/3-0/openapi.yaml).**
 *
 * OpenAPI spec version: 3.0
 * 
 * Generated by:https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api.git
 * AmazonAdvertisingApi Codegen version: 3.0.51
 */
/**
 * NOTE: This class is auto generated by the AmazonAdvertisingApi code generator program.
 *https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api
 * Do not edit the class manually.
 */

namespace AmazonAdvertisingApi\Api;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use AmazonAdvertisingApi\ApiException;
use AmazonAdvertisingApi\Configuration;
use AmazonAdvertisingApi\HeaderSelector;
use AmazonAdvertisingApi\ObjectSerializer;

/**
 * CampaignsApi Class Doc Comment
 *
 * @category Class
 * @package  AmazonAdvertisingApi
 * @author   vv_guo
 * @link    https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api
 */
class CampaignsApi
{
    /**
     * @var ClientInterface
     */
    protected $client;

    /**
     * @var Configuration
     */
    protected $config;

    /**
     * @var HeaderSelector
     */
    protected $headerSelector;

    /**
     * @param ClientInterface $client
     * @param Configuration   $config
     * @param HeaderSelector  $selector
     */
    public function __construct(
        ClientInterface $client = null,
        Configuration $config = null,
        HeaderSelector $selector = null
    ) {
        $this->client = $client ?: new Client();
        $this->config = $config ?: new Configuration();
        $this->headerSelector = $selector ?: new HeaderSelector();
    }

    /**
     * @return Configuration
     */
    public function getConfig()
    {
        return $this->config;
    }

    /**
     * Operation archiveCampaign
     *
     * Sets the campaign status to archived.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the campaign. (required)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \AmazonAdvertisingApi\Model\CampaignResponse
     */
    public function archiveCampaign($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        list($response) = $this->archiveCampaignWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id);
        return $response;
    }

    /**
     * Operation archiveCampaignWithHttpInfo
     *
     * Sets the campaign status to archived.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the campaign. (required)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \AmazonAdvertisingApi\Model\CampaignResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function archiveCampaignWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        $returnType = '\AmazonAdvertisingApi\Model\CampaignResponse';
        $request = $this->archiveCampaignRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\CampaignResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation archiveCampaignAsync
     *
     * Sets the campaign status to archived.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the campaign. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function archiveCampaignAsync($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        return $this->archiveCampaignAsyncWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation archiveCampaignAsyncWithHttpInfo
     *
     * Sets the campaign status to archived.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the campaign. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function archiveCampaignAsyncWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        $returnType = '\AmazonAdvertisingApi\Model\CampaignResponse';
        $request = $this->archiveCampaignRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'archiveCampaign'
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the campaign. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function archiveCampaignRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        // verify the required parameter 'amazon_advertising_api_client_id' is set
        if ($amazon_advertising_api_client_id === null || (is_array($amazon_advertising_api_client_id) && count($amazon_advertising_api_client_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_client_id when calling archiveCampaign'
            );
        }
        // verify the required parameter 'amazon_advertising_api_scope' is set
        if ($amazon_advertising_api_scope === null || (is_array($amazon_advertising_api_scope) && count($amazon_advertising_api_scope) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_scope when calling archiveCampaign'
            );
        }
        // verify the required parameter 'campaign_id' is set
        if ($campaign_id === null || (is_array($campaign_id) && count($campaign_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $campaign_id when calling archiveCampaign'
            );
        }

        $resourcePath = '/sd/campaigns/{campaignId}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($amazon_advertising_api_client_id !== null) {
            $headerParams['Amazon-Advertising-API-ClientId'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_client_id);
        }
        // header params
        if ($amazon_advertising_api_scope !== null) {
            $headerParams['Amazon-Advertising-API-Scope'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_scope);
        }

        // path params
        if ($campaign_id !== null) {
            $resourcePath = str_replace(
                '{' . 'campaignId' . '}',
                ObjectSerializer::toPathValue($campaign_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

            // // this endpoint requires Bearer token
            if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
            }
        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'DELETE',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation createCampaigns
     *
     * Creates one or more campaigns.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  \AmazonAdvertisingApi\Model\CreateCampaign[] $body An array of Campaign objects. For each object, specify required fields and their values. Required fields are &#x60;name&#x60;, &#x60;tactic&#x60;, &#x60;state&#x60;, and &#x60;startDate&#x60;. Maximum length of the array is 100 objects. If you don&#x27;t specify a &#x60;budget&#x60;, it will be set as the [default budget for your region](https://advertising.amazon.com/API/docs/en-us/concepts/limits#default-budgets). Campaign names must be unique across SD, SB, and SP.
  If you are using Optimization rules, the following campaign budget must be at least:
  - 5x the value of any COST_PER_ORDER threshold.
  - 10x the value of any COST_PER_THOUSAND_VIEWABLE_IMPRESSIONS threshold.
  - 20x the value of any COST_PER_CLICK threshold.
 (optional)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \AmazonAdvertisingApi\Model\CampaignResponse[]
     */
    public function createCampaigns($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body = null)
    {
        list($response) = $this->createCampaignsWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body);
        return $response;
    }

    /**
     * Operation createCampaignsWithHttpInfo
     *
     * Creates one or more campaigns.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  \AmazonAdvertisingApi\Model\CreateCampaign[] $body An array of Campaign objects. For each object, specify required fields and their values. Required fields are &#x60;name&#x60;, &#x60;tactic&#x60;, &#x60;state&#x60;, and &#x60;startDate&#x60;. Maximum length of the array is 100 objects. If you don&#x27;t specify a &#x60;budget&#x60;, it will be set as the [default budget for your region](https://advertising.amazon.com/API/docs/en-us/concepts/limits#default-budgets). Campaign names must be unique across SD, SB, and SP.
  If you are using Optimization rules, the following campaign budget must be at least:
  - 5x the value of any COST_PER_ORDER threshold.
  - 10x the value of any COST_PER_THOUSAND_VIEWABLE_IMPRESSIONS threshold.
  - 20x the value of any COST_PER_CLICK threshold.
 (optional)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \AmazonAdvertisingApi\Model\CampaignResponse[], HTTP status code, HTTP response headers (array of strings)
     */
    public function createCampaignsWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body = null)
    {
        $returnType = '\AmazonAdvertisingApi\Model\CampaignResponse[]';
        $request = $this->createCampaignsRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 207:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\CampaignResponse[]',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 422:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation createCampaignsAsync
     *
     * Creates one or more campaigns.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  \AmazonAdvertisingApi\Model\CreateCampaign[] $body An array of Campaign objects. For each object, specify required fields and their values. Required fields are &#x60;name&#x60;, &#x60;tactic&#x60;, &#x60;state&#x60;, and &#x60;startDate&#x60;. Maximum length of the array is 100 objects. If you don&#x27;t specify a &#x60;budget&#x60;, it will be set as the [default budget for your region](https://advertising.amazon.com/API/docs/en-us/concepts/limits#default-budgets). Campaign names must be unique across SD, SB, and SP.
  If you are using Optimization rules, the following campaign budget must be at least:
  - 5x the value of any COST_PER_ORDER threshold.
  - 10x the value of any COST_PER_THOUSAND_VIEWABLE_IMPRESSIONS threshold.
  - 20x the value of any COST_PER_CLICK threshold.
 (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function createCampaignsAsync($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body = null)
    {
        return $this->createCampaignsAsyncWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation createCampaignsAsyncWithHttpInfo
     *
     * Creates one or more campaigns.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  \AmazonAdvertisingApi\Model\CreateCampaign[] $body An array of Campaign objects. For each object, specify required fields and their values. Required fields are &#x60;name&#x60;, &#x60;tactic&#x60;, &#x60;state&#x60;, and &#x60;startDate&#x60;. Maximum length of the array is 100 objects. If you don&#x27;t specify a &#x60;budget&#x60;, it will be set as the [default budget for your region](https://advertising.amazon.com/API/docs/en-us/concepts/limits#default-budgets). Campaign names must be unique across SD, SB, and SP.
  If you are using Optimization rules, the following campaign budget must be at least:
  - 5x the value of any COST_PER_ORDER threshold.
  - 10x the value of any COST_PER_THOUSAND_VIEWABLE_IMPRESSIONS threshold.
  - 20x the value of any COST_PER_CLICK threshold.
 (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function createCampaignsAsyncWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body = null)
    {
        $returnType = '\AmazonAdvertisingApi\Model\CampaignResponse[]';
        $request = $this->createCampaignsRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'createCampaigns'
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  \AmazonAdvertisingApi\Model\CreateCampaign[] $body An array of Campaign objects. For each object, specify required fields and their values. Required fields are &#x60;name&#x60;, &#x60;tactic&#x60;, &#x60;state&#x60;, and &#x60;startDate&#x60;. Maximum length of the array is 100 objects. If you don&#x27;t specify a &#x60;budget&#x60;, it will be set as the [default budget for your region](https://advertising.amazon.com/API/docs/en-us/concepts/limits#default-budgets). Campaign names must be unique across SD, SB, and SP.
  If you are using Optimization rules, the following campaign budget must be at least:
  - 5x the value of any COST_PER_ORDER threshold.
  - 10x the value of any COST_PER_THOUSAND_VIEWABLE_IMPRESSIONS threshold.
  - 20x the value of any COST_PER_CLICK threshold.
 (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function createCampaignsRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body = null)
    {
        // verify the required parameter 'amazon_advertising_api_client_id' is set
        if ($amazon_advertising_api_client_id === null || (is_array($amazon_advertising_api_client_id) && count($amazon_advertising_api_client_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_client_id when calling createCampaigns'
            );
        }
        // verify the required parameter 'amazon_advertising_api_scope' is set
        if ($amazon_advertising_api_scope === null || (is_array($amazon_advertising_api_scope) && count($amazon_advertising_api_scope) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_scope when calling createCampaigns'
            );
        }

        $resourcePath = '/sd/campaigns';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($amazon_advertising_api_client_id !== null) {
            $headerParams['Amazon-Advertising-API-ClientId'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_client_id);
        }
        // header params
        if ($amazon_advertising_api_scope !== null) {
            $headerParams['Amazon-Advertising-API-Scope'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_scope);
        }


        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

            // // this endpoint requires Bearer token
            if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
            }
        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getCampaign
     *
     * Gets a requested campaign.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the requested campaign. (required)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \AmazonAdvertisingApi\Model\Campaign
     */
    public function getCampaign($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        list($response) = $this->getCampaignWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id);
        return $response;
    }

    /**
     * Operation getCampaignWithHttpInfo
     *
     * Gets a requested campaign.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the requested campaign. (required)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \AmazonAdvertisingApi\Model\Campaign, HTTP status code, HTTP response headers (array of strings)
     */
    public function getCampaignWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        $returnType = '\AmazonAdvertisingApi\Model\Campaign';
        $request = $this->getCampaignRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Campaign',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getCampaignAsync
     *
     * Gets a requested campaign.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the requested campaign. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCampaignAsync($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        return $this->getCampaignAsyncWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getCampaignAsyncWithHttpInfo
     *
     * Gets a requested campaign.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the requested campaign. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCampaignAsyncWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        $returnType = '\AmazonAdvertisingApi\Model\Campaign';
        $request = $this->getCampaignRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getCampaign'
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the requested campaign. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function getCampaignRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        // verify the required parameter 'amazon_advertising_api_client_id' is set
        if ($amazon_advertising_api_client_id === null || (is_array($amazon_advertising_api_client_id) && count($amazon_advertising_api_client_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_client_id when calling getCampaign'
            );
        }
        // verify the required parameter 'amazon_advertising_api_scope' is set
        if ($amazon_advertising_api_scope === null || (is_array($amazon_advertising_api_scope) && count($amazon_advertising_api_scope) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_scope when calling getCampaign'
            );
        }
        // verify the required parameter 'campaign_id' is set
        if ($campaign_id === null || (is_array($campaign_id) && count($campaign_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $campaign_id when calling getCampaign'
            );
        }

        $resourcePath = '/sd/campaigns/{campaignId}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($amazon_advertising_api_client_id !== null) {
            $headerParams['Amazon-Advertising-API-ClientId'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_client_id);
        }
        // header params
        if ($amazon_advertising_api_scope !== null) {
            $headerParams['Amazon-Advertising-API-Scope'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_scope);
        }

        // path params
        if ($campaign_id !== null) {
            $resourcePath = str_replace(
                '{' . 'campaignId' . '}',
                ObjectSerializer::toPathValue($campaign_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

            // // this endpoint requires Bearer token
            if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
            }
        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getCampaignResponseEx
     *
     * Gets extended information for a requested campaign.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the requested campaign. (required)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \AmazonAdvertisingApi\Model\CampaignResponseEx
     */
    public function getCampaignResponseEx($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        list($response) = $this->getCampaignResponseExWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id);
        return $response;
    }

    /**
     * Operation getCampaignResponseExWithHttpInfo
     *
     * Gets extended information for a requested campaign.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the requested campaign. (required)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \AmazonAdvertisingApi\Model\CampaignResponseEx, HTTP status code, HTTP response headers (array of strings)
     */
    public function getCampaignResponseExWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        $returnType = '\AmazonAdvertisingApi\Model\CampaignResponseEx';
        $request = $this->getCampaignResponseExRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\CampaignResponseEx',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 404:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getCampaignResponseExAsync
     *
     * Gets extended information for a requested campaign.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the requested campaign. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCampaignResponseExAsync($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        return $this->getCampaignResponseExAsyncWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getCampaignResponseExAsyncWithHttpInfo
     *
     * Gets extended information for a requested campaign.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the requested campaign. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getCampaignResponseExAsyncWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        $returnType = '\AmazonAdvertisingApi\Model\CampaignResponseEx';
        $request = $this->getCampaignResponseExRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getCampaignResponseEx'
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $campaign_id The identifier of the requested campaign. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function getCampaignResponseExRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $campaign_id)
    {
        // verify the required parameter 'amazon_advertising_api_client_id' is set
        if ($amazon_advertising_api_client_id === null || (is_array($amazon_advertising_api_client_id) && count($amazon_advertising_api_client_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_client_id when calling getCampaignResponseEx'
            );
        }
        // verify the required parameter 'amazon_advertising_api_scope' is set
        if ($amazon_advertising_api_scope === null || (is_array($amazon_advertising_api_scope) && count($amazon_advertising_api_scope) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_scope when calling getCampaignResponseEx'
            );
        }
        // verify the required parameter 'campaign_id' is set
        if ($campaign_id === null || (is_array($campaign_id) && count($campaign_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $campaign_id when calling getCampaignResponseEx'
            );
        }

        $resourcePath = '/sd/campaigns/extended/{campaignId}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($amazon_advertising_api_client_id !== null) {
            $headerParams['Amazon-Advertising-API-ClientId'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_client_id);
        }
        // header params
        if ($amazon_advertising_api_scope !== null) {
            $headerParams['Amazon-Advertising-API-Scope'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_scope);
        }

        // path params
        if ($campaign_id !== null) {
            $resourcePath = str_replace(
                '{' . 'campaignId' . '}',
                ObjectSerializer::toPathValue($campaign_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

            // // this endpoint requires Bearer token
            if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
            }
        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation listCampaigns
     *
     * Gets a list of campaigns.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $start_index Optional. Sets a cursor into the requested set of campaigns. Use in conjunction with the &#x60;count&#x60; parameter to control pagination of the returned array. 0-indexed record offset for the result set, defaults to 0. (optional, default to 0)
     * @param  int $count Optional. Sets the number of Campaign objects in the returned array. Use in conjunction with the &#x60;startIndex&#x60; parameter to control pagination. For example, to return the first ten campaigns set &#x60;startIndex&#x3D;0&#x60; and &#x60;count&#x3D;10&#x60;. To return the next ten campaigns, set &#x60;startIndex&#x3D;10&#x60; and &#x60;count&#x3D;10&#x60;, and so on. Defaults to max page size. (optional)
     * @param  string $state_filter Optional. The returned array is filtered to include only campaigns with state set to one of the values in the specified comma-delimited list. (optional, default to enabled, paused, archived)
     * @param  string $name Optional. The returned array includes only campaign with the specified name using an exact string match. (optional)
     * @param  string $campaign_id_filter Optional. The returned array includes only campaigns with identifiers matching those specified in the comma-delimited string. (optional)
     * @param  string $portfolio_id_filter Optional. The returned array includes only campaigns associated with Portfolio identifiers matching those specified in the comma-delimited string. (optional)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \AmazonAdvertisingApi\Model\Campaign[]
     */
    public function listCampaigns($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index = '0', $count = null, $state_filter = 'enabled, paused, archived', $name = null, $campaign_id_filter = null, $portfolio_id_filter = null)
    {
        list($response) = $this->listCampaignsWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index, $count, $state_filter, $name, $campaign_id_filter, $portfolio_id_filter);
        return $response;
    }

    /**
     * Operation listCampaignsWithHttpInfo
     *
     * Gets a list of campaigns.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $start_index Optional. Sets a cursor into the requested set of campaigns. Use in conjunction with the &#x60;count&#x60; parameter to control pagination of the returned array. 0-indexed record offset for the result set, defaults to 0. (optional, default to 0)
     * @param  int $count Optional. Sets the number of Campaign objects in the returned array. Use in conjunction with the &#x60;startIndex&#x60; parameter to control pagination. For example, to return the first ten campaigns set &#x60;startIndex&#x3D;0&#x60; and &#x60;count&#x3D;10&#x60;. To return the next ten campaigns, set &#x60;startIndex&#x3D;10&#x60; and &#x60;count&#x3D;10&#x60;, and so on. Defaults to max page size. (optional)
     * @param  string $state_filter Optional. The returned array is filtered to include only campaigns with state set to one of the values in the specified comma-delimited list. (optional, default to enabled, paused, archived)
     * @param  string $name Optional. The returned array includes only campaign with the specified name using an exact string match. (optional)
     * @param  string $campaign_id_filter Optional. The returned array includes only campaigns with identifiers matching those specified in the comma-delimited string. (optional)
     * @param  string $portfolio_id_filter Optional. The returned array includes only campaigns associated with Portfolio identifiers matching those specified in the comma-delimited string. (optional)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \AmazonAdvertisingApi\Model\Campaign[], HTTP status code, HTTP response headers (array of strings)
     */
    public function listCampaignsWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index = '0', $count = null, $state_filter = 'enabled, paused, archived', $name = null, $campaign_id_filter = null, $portfolio_id_filter = null)
    {
        $returnType = '\AmazonAdvertisingApi\Model\Campaign[]';
        $request = $this->listCampaignsRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index, $count, $state_filter, $name, $campaign_id_filter, $portfolio_id_filter);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Campaign[]',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 422:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation listCampaignsAsync
     *
     * Gets a list of campaigns.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $start_index Optional. Sets a cursor into the requested set of campaigns. Use in conjunction with the &#x60;count&#x60; parameter to control pagination of the returned array. 0-indexed record offset for the result set, defaults to 0. (optional, default to 0)
     * @param  int $count Optional. Sets the number of Campaign objects in the returned array. Use in conjunction with the &#x60;startIndex&#x60; parameter to control pagination. For example, to return the first ten campaigns set &#x60;startIndex&#x3D;0&#x60; and &#x60;count&#x3D;10&#x60;. To return the next ten campaigns, set &#x60;startIndex&#x3D;10&#x60; and &#x60;count&#x3D;10&#x60;, and so on. Defaults to max page size. (optional)
     * @param  string $state_filter Optional. The returned array is filtered to include only campaigns with state set to one of the values in the specified comma-delimited list. (optional, default to enabled, paused, archived)
     * @param  string $name Optional. The returned array includes only campaign with the specified name using an exact string match. (optional)
     * @param  string $campaign_id_filter Optional. The returned array includes only campaigns with identifiers matching those specified in the comma-delimited string. (optional)
     * @param  string $portfolio_id_filter Optional. The returned array includes only campaigns associated with Portfolio identifiers matching those specified in the comma-delimited string. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function listCampaignsAsync($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index = '0', $count = null, $state_filter = 'enabled, paused, archived', $name = null, $campaign_id_filter = null, $portfolio_id_filter = null)
    {
        return $this->listCampaignsAsyncWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index, $count, $state_filter, $name, $campaign_id_filter, $portfolio_id_filter)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation listCampaignsAsyncWithHttpInfo
     *
     * Gets a list of campaigns.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $start_index Optional. Sets a cursor into the requested set of campaigns. Use in conjunction with the &#x60;count&#x60; parameter to control pagination of the returned array. 0-indexed record offset for the result set, defaults to 0. (optional, default to 0)
     * @param  int $count Optional. Sets the number of Campaign objects in the returned array. Use in conjunction with the &#x60;startIndex&#x60; parameter to control pagination. For example, to return the first ten campaigns set &#x60;startIndex&#x3D;0&#x60; and &#x60;count&#x3D;10&#x60;. To return the next ten campaigns, set &#x60;startIndex&#x3D;10&#x60; and &#x60;count&#x3D;10&#x60;, and so on. Defaults to max page size. (optional)
     * @param  string $state_filter Optional. The returned array is filtered to include only campaigns with state set to one of the values in the specified comma-delimited list. (optional, default to enabled, paused, archived)
     * @param  string $name Optional. The returned array includes only campaign with the specified name using an exact string match. (optional)
     * @param  string $campaign_id_filter Optional. The returned array includes only campaigns with identifiers matching those specified in the comma-delimited string. (optional)
     * @param  string $portfolio_id_filter Optional. The returned array includes only campaigns associated with Portfolio identifiers matching those specified in the comma-delimited string. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function listCampaignsAsyncWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index = '0', $count = null, $state_filter = 'enabled, paused, archived', $name = null, $campaign_id_filter = null, $portfolio_id_filter = null)
    {
        $returnType = '\AmazonAdvertisingApi\Model\Campaign[]';
        $request = $this->listCampaignsRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index, $count, $state_filter, $name, $campaign_id_filter, $portfolio_id_filter);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'listCampaigns'
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $start_index Optional. Sets a cursor into the requested set of campaigns. Use in conjunction with the &#x60;count&#x60; parameter to control pagination of the returned array. 0-indexed record offset for the result set, defaults to 0. (optional, default to 0)
     * @param  int $count Optional. Sets the number of Campaign objects in the returned array. Use in conjunction with the &#x60;startIndex&#x60; parameter to control pagination. For example, to return the first ten campaigns set &#x60;startIndex&#x3D;0&#x60; and &#x60;count&#x3D;10&#x60;. To return the next ten campaigns, set &#x60;startIndex&#x3D;10&#x60; and &#x60;count&#x3D;10&#x60;, and so on. Defaults to max page size. (optional)
     * @param  string $state_filter Optional. The returned array is filtered to include only campaigns with state set to one of the values in the specified comma-delimited list. (optional, default to enabled, paused, archived)
     * @param  string $name Optional. The returned array includes only campaign with the specified name using an exact string match. (optional)
     * @param  string $campaign_id_filter Optional. The returned array includes only campaigns with identifiers matching those specified in the comma-delimited string. (optional)
     * @param  string $portfolio_id_filter Optional. The returned array includes only campaigns associated with Portfolio identifiers matching those specified in the comma-delimited string. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function listCampaignsRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index = '0', $count = null, $state_filter = 'enabled, paused, archived', $name = null, $campaign_id_filter = null, $portfolio_id_filter = null)
    {
        // verify the required parameter 'amazon_advertising_api_client_id' is set
        if ($amazon_advertising_api_client_id === null || (is_array($amazon_advertising_api_client_id) && count($amazon_advertising_api_client_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_client_id when calling listCampaigns'
            );
        }
        // verify the required parameter 'amazon_advertising_api_scope' is set
        if ($amazon_advertising_api_scope === null || (is_array($amazon_advertising_api_scope) && count($amazon_advertising_api_scope) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_scope when calling listCampaigns'
            );
        }

        $resourcePath = '/sd/campaigns';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        if ($start_index !== null) {
            $queryParams['startIndex'] = ObjectSerializer::toQueryValue($start_index, 'int32');
        }
        // query params
        if ($count !== null) {
            $queryParams['count'] = ObjectSerializer::toQueryValue($count, 'int32');
        }
        // query params
        if ($state_filter !== null) {
            $queryParams['stateFilter'] = ObjectSerializer::toQueryValue($state_filter, null);
        }
        // query params
        if ($name !== null) {
            $queryParams['name'] = ObjectSerializer::toQueryValue($name, null);
        }
        // query params
        if ($campaign_id_filter !== null) {
            $queryParams['campaignIdFilter'] = ObjectSerializer::toQueryValue($campaign_id_filter, null);
        }
        // query params
        if ($portfolio_id_filter !== null) {
            $queryParams['portfolioIdFilter'] = ObjectSerializer::toQueryValue($portfolio_id_filter, null);
        }
        // header params
        if ($amazon_advertising_api_client_id !== null) {
            $headerParams['Amazon-Advertising-API-ClientId'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_client_id);
        }
        // header params
        if ($amazon_advertising_api_scope !== null) {
            $headerParams['Amazon-Advertising-API-Scope'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_scope);
        }


        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

            // // this endpoint requires Bearer token
            if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
            }
        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation listCampaignsEx
     *
     * Gets a list of campaigns with extended fields.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $start_index Optional. Sets a cursor into the requested set of campaigns. Use in conjunction with the &#x60;count&#x60; parameter to control pagination of the returned array. 0-indexed record offset for the result set, defaults to 0. (optional)
     * @param  int $count Optional. Sets the number of Campaign objects in the returned array. Use in conjunction with the &#x60;startIndex&#x60; parameter to control pagination. For example, to return the first ten campaigns set &#x60;startIndex&#x3D;0&#x60; and &#x60;count&#x3D;10&#x60;. To return the next ten campaigns, set &#x60;startIndex&#x3D;10&#x60; and &#x60;count&#x3D;10&#x60;, and so on. Defaults to max page size. (optional)
     * @param  string $state_filter Optional. The returned array is filtered to include only campaigns with state set to one of the values in the specified comma-delimited list. (optional, default to enabled, paused, archived)
     * @param  string $name Optional. The returned array includes only campaign with the specified name using an exact string match. (optional)
     * @param  string $campaign_id_filter Optional. The returned array includes only campaigns with identifiers matching those specified in the comma-delimited string. (optional)
     * @param  string $portfolio_id_filter Optional. The returned array includes only campaigns associated with Portfolio identifiers matching those specified in the comma-delimited string. (optional)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \AmazonAdvertisingApi\Model\CampaignResponseEx[]
     */
    public function listCampaignsEx($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index = null, $count = null, $state_filter = 'enabled, paused, archived', $name = null, $campaign_id_filter = null, $portfolio_id_filter = null)
    {
        list($response) = $this->listCampaignsExWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index, $count, $state_filter, $name, $campaign_id_filter, $portfolio_id_filter);
        return $response;
    }

    /**
     * Operation listCampaignsExWithHttpInfo
     *
     * Gets a list of campaigns with extended fields.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $start_index Optional. Sets a cursor into the requested set of campaigns. Use in conjunction with the &#x60;count&#x60; parameter to control pagination of the returned array. 0-indexed record offset for the result set, defaults to 0. (optional)
     * @param  int $count Optional. Sets the number of Campaign objects in the returned array. Use in conjunction with the &#x60;startIndex&#x60; parameter to control pagination. For example, to return the first ten campaigns set &#x60;startIndex&#x3D;0&#x60; and &#x60;count&#x3D;10&#x60;. To return the next ten campaigns, set &#x60;startIndex&#x3D;10&#x60; and &#x60;count&#x3D;10&#x60;, and so on. Defaults to max page size. (optional)
     * @param  string $state_filter Optional. The returned array is filtered to include only campaigns with state set to one of the values in the specified comma-delimited list. (optional, default to enabled, paused, archived)
     * @param  string $name Optional. The returned array includes only campaign with the specified name using an exact string match. (optional)
     * @param  string $campaign_id_filter Optional. The returned array includes only campaigns with identifiers matching those specified in the comma-delimited string. (optional)
     * @param  string $portfolio_id_filter Optional. The returned array includes only campaigns associated with Portfolio identifiers matching those specified in the comma-delimited string. (optional)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \AmazonAdvertisingApi\Model\CampaignResponseEx[], HTTP status code, HTTP response headers (array of strings)
     */
    public function listCampaignsExWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index = null, $count = null, $state_filter = 'enabled, paused, archived', $name = null, $campaign_id_filter = null, $portfolio_id_filter = null)
    {
        $returnType = '\AmazonAdvertisingApi\Model\CampaignResponseEx[]';
        $request = $this->listCampaignsExRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index, $count, $state_filter, $name, $campaign_id_filter, $portfolio_id_filter);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\CampaignResponseEx[]',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 422:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation listCampaignsExAsync
     *
     * Gets a list of campaigns with extended fields.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $start_index Optional. Sets a cursor into the requested set of campaigns. Use in conjunction with the &#x60;count&#x60; parameter to control pagination of the returned array. 0-indexed record offset for the result set, defaults to 0. (optional)
     * @param  int $count Optional. Sets the number of Campaign objects in the returned array. Use in conjunction with the &#x60;startIndex&#x60; parameter to control pagination. For example, to return the first ten campaigns set &#x60;startIndex&#x3D;0&#x60; and &#x60;count&#x3D;10&#x60;. To return the next ten campaigns, set &#x60;startIndex&#x3D;10&#x60; and &#x60;count&#x3D;10&#x60;, and so on. Defaults to max page size. (optional)
     * @param  string $state_filter Optional. The returned array is filtered to include only campaigns with state set to one of the values in the specified comma-delimited list. (optional, default to enabled, paused, archived)
     * @param  string $name Optional. The returned array includes only campaign with the specified name using an exact string match. (optional)
     * @param  string $campaign_id_filter Optional. The returned array includes only campaigns with identifiers matching those specified in the comma-delimited string. (optional)
     * @param  string $portfolio_id_filter Optional. The returned array includes only campaigns associated with Portfolio identifiers matching those specified in the comma-delimited string. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function listCampaignsExAsync($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index = null, $count = null, $state_filter = 'enabled, paused, archived', $name = null, $campaign_id_filter = null, $portfolio_id_filter = null)
    {
        return $this->listCampaignsExAsyncWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index, $count, $state_filter, $name, $campaign_id_filter, $portfolio_id_filter)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation listCampaignsExAsyncWithHttpInfo
     *
     * Gets a list of campaigns with extended fields.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $start_index Optional. Sets a cursor into the requested set of campaigns. Use in conjunction with the &#x60;count&#x60; parameter to control pagination of the returned array. 0-indexed record offset for the result set, defaults to 0. (optional)
     * @param  int $count Optional. Sets the number of Campaign objects in the returned array. Use in conjunction with the &#x60;startIndex&#x60; parameter to control pagination. For example, to return the first ten campaigns set &#x60;startIndex&#x3D;0&#x60; and &#x60;count&#x3D;10&#x60;. To return the next ten campaigns, set &#x60;startIndex&#x3D;10&#x60; and &#x60;count&#x3D;10&#x60;, and so on. Defaults to max page size. (optional)
     * @param  string $state_filter Optional. The returned array is filtered to include only campaigns with state set to one of the values in the specified comma-delimited list. (optional, default to enabled, paused, archived)
     * @param  string $name Optional. The returned array includes only campaign with the specified name using an exact string match. (optional)
     * @param  string $campaign_id_filter Optional. The returned array includes only campaigns with identifiers matching those specified in the comma-delimited string. (optional)
     * @param  string $portfolio_id_filter Optional. The returned array includes only campaigns associated with Portfolio identifiers matching those specified in the comma-delimited string. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function listCampaignsExAsyncWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index = null, $count = null, $state_filter = 'enabled, paused, archived', $name = null, $campaign_id_filter = null, $portfolio_id_filter = null)
    {
        $returnType = '\AmazonAdvertisingApi\Model\CampaignResponseEx[]';
        $request = $this->listCampaignsExRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index, $count, $state_filter, $name, $campaign_id_filter, $portfolio_id_filter);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'listCampaignsEx'
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  int $start_index Optional. Sets a cursor into the requested set of campaigns. Use in conjunction with the &#x60;count&#x60; parameter to control pagination of the returned array. 0-indexed record offset for the result set, defaults to 0. (optional)
     * @param  int $count Optional. Sets the number of Campaign objects in the returned array. Use in conjunction with the &#x60;startIndex&#x60; parameter to control pagination. For example, to return the first ten campaigns set &#x60;startIndex&#x3D;0&#x60; and &#x60;count&#x3D;10&#x60;. To return the next ten campaigns, set &#x60;startIndex&#x3D;10&#x60; and &#x60;count&#x3D;10&#x60;, and so on. Defaults to max page size. (optional)
     * @param  string $state_filter Optional. The returned array is filtered to include only campaigns with state set to one of the values in the specified comma-delimited list. (optional, default to enabled, paused, archived)
     * @param  string $name Optional. The returned array includes only campaign with the specified name using an exact string match. (optional)
     * @param  string $campaign_id_filter Optional. The returned array includes only campaigns with identifiers matching those specified in the comma-delimited string. (optional)
     * @param  string $portfolio_id_filter Optional. The returned array includes only campaigns associated with Portfolio identifiers matching those specified in the comma-delimited string. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function listCampaignsExRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $start_index = null, $count = null, $state_filter = 'enabled, paused, archived', $name = null, $campaign_id_filter = null, $portfolio_id_filter = null)
    {
        // verify the required parameter 'amazon_advertising_api_client_id' is set
        if ($amazon_advertising_api_client_id === null || (is_array($amazon_advertising_api_client_id) && count($amazon_advertising_api_client_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_client_id when calling listCampaignsEx'
            );
        }
        // verify the required parameter 'amazon_advertising_api_scope' is set
        if ($amazon_advertising_api_scope === null || (is_array($amazon_advertising_api_scope) && count($amazon_advertising_api_scope) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_scope when calling listCampaignsEx'
            );
        }

        $resourcePath = '/sd/campaigns/extended';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        if ($start_index !== null) {
            $queryParams['startIndex'] = ObjectSerializer::toQueryValue($start_index, 'int32');
        }
        // query params
        if ($count !== null) {
            $queryParams['count'] = ObjectSerializer::toQueryValue($count, 'int32');
        }
        // query params
        if ($state_filter !== null) {
            $queryParams['stateFilter'] = ObjectSerializer::toQueryValue($state_filter, null);
        }
        // query params
        if ($name !== null) {
            $queryParams['name'] = ObjectSerializer::toQueryValue($name, null);
        }
        // query params
        if ($campaign_id_filter !== null) {
            $queryParams['campaignIdFilter'] = ObjectSerializer::toQueryValue($campaign_id_filter, null);
        }
        // query params
        if ($portfolio_id_filter !== null) {
            $queryParams['portfolioIdFilter'] = ObjectSerializer::toQueryValue($portfolio_id_filter, null);
        }
        // header params
        if ($amazon_advertising_api_client_id !== null) {
            $headerParams['Amazon-Advertising-API-ClientId'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_client_id);
        }
        // header params
        if ($amazon_advertising_api_scope !== null) {
            $headerParams['Amazon-Advertising-API-Scope'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_scope);
        }


        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

            // // this endpoint requires Bearer token
            if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
            }
        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation updateCampaigns
     *
     * Updates one or more campaigns.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  \AmazonAdvertisingApi\Model\UpdateCampaign[] $body An array of Campaign objects. For each object, specify a campaign identifier and mutable fields with their updated values. The mutable fields are &#x60;name&#x60;, &#x60;state&#x60;, &#x60;budget&#x60;, &#x60;startDate&#x60;, and &#x60;endDate&#x60;. Maximum length of the array is 100 objects. (optional)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \AmazonAdvertisingApi\Model\CampaignResponse[]
     */
    public function updateCampaigns($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body = null)
    {
        list($response) = $this->updateCampaignsWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body);
        return $response;
    }

    /**
     * Operation updateCampaignsWithHttpInfo
     *
     * Updates one or more campaigns.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  \AmazonAdvertisingApi\Model\UpdateCampaign[] $body An array of Campaign objects. For each object, specify a campaign identifier and mutable fields with their updated values. The mutable fields are &#x60;name&#x60;, &#x60;state&#x60;, &#x60;budget&#x60;, &#x60;startDate&#x60;, and &#x60;endDate&#x60;. Maximum length of the array is 100 objects. (optional)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \AmazonAdvertisingApi\Model\CampaignResponse[], HTTP status code, HTTP response headers (array of strings)
     */
    public function updateCampaignsWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body = null)
    {
        $returnType = '\AmazonAdvertisingApi\Model\CampaignResponse[]';
        $request = $this->updateCampaignsRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 207:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\CampaignResponse[]',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 422:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\Error',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation updateCampaignsAsync
     *
     * Updates one or more campaigns.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  \AmazonAdvertisingApi\Model\UpdateCampaign[] $body An array of Campaign objects. For each object, specify a campaign identifier and mutable fields with their updated values. The mutable fields are &#x60;name&#x60;, &#x60;state&#x60;, &#x60;budget&#x60;, &#x60;startDate&#x60;, and &#x60;endDate&#x60;. Maximum length of the array is 100 objects. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateCampaignsAsync($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body = null)
    {
        return $this->updateCampaignsAsyncWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updateCampaignsAsyncWithHttpInfo
     *
     * Updates one or more campaigns.
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  \AmazonAdvertisingApi\Model\UpdateCampaign[] $body An array of Campaign objects. For each object, specify a campaign identifier and mutable fields with their updated values. The mutable fields are &#x60;name&#x60;, &#x60;state&#x60;, &#x60;budget&#x60;, &#x60;startDate&#x60;, and &#x60;endDate&#x60;. Maximum length of the array is 100 objects. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateCampaignsAsyncWithHttpInfo($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body = null)
    {
        $returnType = '\AmazonAdvertisingApi\Model\CampaignResponse[]';
        $request = $this->updateCampaignsRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'updateCampaigns'
     *
     * @param  string $amazon_advertising_api_client_id The identifier of a client associated with a \&quot;Login with Amazon\&quot; account. (required)
     * @param  string $amazon_advertising_api_scope The identifier of a profile associated with the advertiser account. Use &#x60;GET&#x60; method on Profiles resource to list profiles associated with the access token passed in the HTTP Authorization header. (required)
     * @param  \AmazonAdvertisingApi\Model\UpdateCampaign[] $body An array of Campaign objects. For each object, specify a campaign identifier and mutable fields with their updated values. The mutable fields are &#x60;name&#x60;, &#x60;state&#x60;, &#x60;budget&#x60;, &#x60;startDate&#x60;, and &#x60;endDate&#x60;. Maximum length of the array is 100 objects. (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function updateCampaignsRequest($amazon_advertising_api_client_id, $amazon_advertising_api_scope, $body = null)
    {
        // verify the required parameter 'amazon_advertising_api_client_id' is set
        if ($amazon_advertising_api_client_id === null || (is_array($amazon_advertising_api_client_id) && count($amazon_advertising_api_client_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_client_id when calling updateCampaigns'
            );
        }
        // verify the required parameter 'amazon_advertising_api_scope' is set
        if ($amazon_advertising_api_scope === null || (is_array($amazon_advertising_api_scope) && count($amazon_advertising_api_scope) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_scope when calling updateCampaigns'
            );
        }

        $resourcePath = '/sd/campaigns';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($amazon_advertising_api_client_id !== null) {
            $headerParams['Amazon-Advertising-API-ClientId'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_client_id);
        }
        // header params
        if ($amazon_advertising_api_scope !== null) {
            $headerParams['Amazon-Advertising-API-Scope'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_scope);
        }


        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                ['application/json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }

            // // this endpoint requires Bearer token
            if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
            }
        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'PUT',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Create http client option
     *
     * @throws \RuntimeException on file opening failure
     * @return array of http client options
     */
    protected function createHttpClientOption()
    {
        $options = [];
        if ($this->config->getDebug()) {
            $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
            if (!$options[RequestOptions::DEBUG]) {
                throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
            }
        }

        return $options;
    }
}
